#	MountServer - mount a server
#
#	Usage:	MountServer server
#
#	Status:	MountServer may return the following status values:
#
#			0		the server was mounted
#			1		error
#			4		the user canceled
#
#	MountServer mounts a a server volume.
#	If the volume is not already mounted,
#	it asks for a password for the volume.
#
#	© Apple Computer, Inc. 1988
#	All rights reserved.

Set Exit 0
Begin
	Set Server "{1}"

	# make sure that names are formed properly

	If "{Server}" =~ /([Â:]*)¨1:([Â:]+)¨2:Ç0,1È/
		Set Zone "*"
		Set Server "{¨1}"
		Set Volume "{¨2}"
	Else If "{Server}" =~ /([Â:]*)¨1:([Â:]+)¨2:([Â:]+)¨3:Ç0,1È/
		Set Zone "{¨1}"
		Set Server "{¨2}"
		Set Volume "{¨3}"
	Else
		Exit 1
	End

	# check if the volume is mounted

	If `Exists "{Volume}:"` == ""
		# handle case where one volume from this server is already mounted (or empty password)
		Choose "{Zone}:{Server}:{Volume}" ³ Dev:Null
		If {Status} ­ 0
			Set IgnoreCmdPeriod 1
			Set Password "`CoolRequest -h -p "Enter your password on the Ò{Server}Ó server, please:"; Set GetPasswordStatus {Status}`"
			Set IgnoreCmdPeriod 0
			Exit 4 If {GetPasswordStatus} == 4
			Exit 1 If {GetPasswordStatus} ­ 0
	
			Choose "{Zone}:{Server}:{Volume}" -pw "{Password}"
			Unset Password
			Exit 1 If {Status} ­ 0
		End
	End
End · Dev:Null
